<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>文章列表--layui后台管理模板 2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="resources/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form" id="dataFrm">
    <div class="layui-form-item layui-row">
        <div class="layui-input-block">
            编号</span><input type="text" id="chanNo" style="color: #a3b8c4" class="layui-input chanNo" name="chanNo" lay-verify="required" readonly="readonly">
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-input-block">
            客户名称<span style="color:red">* </span><input type="text" style="color: #a3b8c4" readonly="readonly" id="chanCustName" class="layui-input chanCustName" name="chanCustName" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <!--<label class="layui-form-label"></label>-->
        <div class="layui-input-block">
            机会来源 <input type="text" class="layui-input chanSource" id="chanSource" name="chanSource" style="color: #a3b8c4" readonly="readonly" placeholder="无">
            成功率<span style="color:red">* </span><input type="text" style="color: #a3b8c4" id="chanRate" readonly="readonly" class="layui-input chanRate" name="chanRate" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-input-block">
            概要<span style="color:red">* </span><input type="text" style="color: #a3b8c4" id="chanTitle" readonly="readonly" class="layui-input chanTitle" name="chanTitle" lay-verify="required" >
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <!--<label class="layui-form-label">联系人:</label>-->
        <div class="layui-input-block">
            联系人<input type="text" class="layui-input chanLinkman" id="chanLinkman" name="chanLinkman" placeholder="无" style="color: #a3b8c4" readonly="readonly">
            联系电话<input type="text" class="layui-input chanTelephone" id="chanTelephone" name="chanTelephone" placeholder="无" style="color: #a3b8c4" readonly="readonly">
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-input-block">
            机会描述<span style="color:red">* </span><input type="text" style="color: #a3b8c4;height: 100px" id="chanDescription" readonly="readonly" class="layui-input chanDescription" name="chanDescription" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-input-block">
            创建人<span style="color:red">* </span><input type="text" class="layui-input chanCreateBy" style="color: #a3b8c4" readonly="readonly" id="chanCreateBy" name="chanCreateBy" lay-verify="required"  th:value="${session.USER_SESSION.realname}">
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-input-block">
            创建时间<span style="color:red">* </span><input type="text" class="layui-input chanCreateDate" style="color: #a3b8c4" readonly="readonly" id="chanCreateDate" name="chanCreateDate" lay-verify="required"  th:value="${#dates.format(new java.util.Date().getTime(), 'yyyy-MM-dd HH:mm:ss')}">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <div class="layui-input-block">
            指派者<input type="text" class="layui-input chanDueTo"  style="color: #a3b8c4" id="chanDueTo" name="chanDueTo" readonly="readonly">
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-input-block">
            指派时间<input type="text" class="layui-input chanDueDate"  style="color: #a3b8c4" id="chanDueDate" name="chanDueDate" readonly="readonly">
        </div>
    </div>
    <hr>

    <table id="devPlan" lay-filter="devPlan">
        <tr id="plan" name="" class="plan" lay-filter="plan"></tr>
    </table>
        日期<span style="color:red">* </span>
        <input type="text" style="height:30px;width:90px;color: #a3b8c4" readonly="readonly" id="planDate"  th:value="${#dates.format(new java.util.Date().getTime(), 'yyyy-MM-dd')}">
        计划项<span style="color:red">* </span>
        <input type="text" style="height:30px;width:200px" id="planItem"  lay-verify="required">


    <!--操作-->
    <script type="text/html" id="devPlanListBar">
        <a class="layui-btn layui-btn-xs development layui-icon-rss" lay-event="editDevPlan">修改</a>
    </script>

    <!--&lt;!&ndash;测试的按钮，动态&ndash;&gt;-->
    <!--<input type="button" id="btn1" value="按钮">-->
    <!--<button id="btn2">按钮2</button>-->
    <!--<a class="layui-btn layui-btn-xs development layui-icon-rss" id="btn3">按钮3</a>-->
    <!--输入:<input type="text" style="width: 200px" id="text1" value="我是测试的" >-->

</form>
<button id="save" class="layui-btn-warm" style="height:20px">保存计划</button>
<div>
    <button id="executePlan" class="layui-btn-danger">执行计划</button>
</div>
<div class="layui-form-item layui-row layui-col-xs12">
    <!--<div class="layui-input-block">-->
        <!--<button class="layui-btn layui-btn-sm" id="updateSaleChance">保存</button>-->
        <!--<button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">取消</button>-->
    <!--</div>-->
</div>

<script type="text/javascript" src="resources/layui/layui.js"></script>
<script th:inline="none">
    layui.use(['form','layer','laydate','table','laytpl','upload'],function() {
        var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table,
            upload=layui.upload;

        //获取当前行数据，并且实现删除，编辑等功能
        table.on("tool(devPlan)",function (obj) {
            //获取当前行的数据
            var data=obj.data;
            switch (obj.event){//得到的就是点击lay-event中的值
                case 'editDevPlan':
                    editDevPlan(data);
                    break;
            }
        });
        //得到销售机会的编号
        var chanNo=$("#chanNo").val();
        //底部的开发计划列表
        var tableIns = table.render({
            elem: '#devPlan',//渲染的表格
            url : 'findDevPlanByChanNo.do',
            // page : true,
            // limit : 10,
            // limits : [8,10,15,20,25],
            where: {chanNo:chanNo},
            id : "devPlanListTable",
            cols : [[
                //{field: 'planNo', title: '计划编号',align:"center",width: 150},
                {field: 'planDate', title: '日期',align:"center",width: 170},
                {field: 'planItem', title: '计划项',align:"center",width:850},
                {title: '操作', width:200, templet:'#devPlanListBar',fixed:"right",align:"center"}
            ]]
        });
        //点击保存计划按钮
        $("#save").click(function () {
            var chanNo=$("#chanNo").val();
            var planDate=$("#planDate").val();
            var planItem=$("#planItem").val();
            if(planItem!=null&&planItem!=''){
                $.ajax({
                    type:"POST",
                    url:"saveDevPlan.do",
                    data:{planChanNo:chanNo,planDate:planDate,planItem:planItem},
                    success:function (res) {
                        if(res.code=5004){
                            layer.msg(res.msg);
                            table.reload("devPlanListTable")
                        }else{
                            layer.msg(res.msg);
                        }
                    }
                });
            }
        });
        //修改
        function editDevPlan(data) {
            var planNo=data.planNo;
            var planItem=data.planItem;
            var planDate=data.planDate;
            var index=layui.layer.open({
                title:"修改计划",
                type:2,
                area:['500px','300px'],
                content:"toImportPlan.do",
                success:function (layero,index) {
                    var body =layui.layer.getChildFrame('body', index);//少了这个是不能从父页面向子页面传值的
                    body.contents().find("#planNo").val(planNo);
                    body.contents().find("#planItem").val(planItem);
                    body.contents().find("#planDate").val(planDate);
                }
            });
        }

        //保存计划项
        $("#updateSaleChance").click(function () {
            var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
            //实际使用时的提交数据
            var params=$("#dataFrm").serialize();//序列化整个表单
            console.log(params);
            $.post("",params,function (res) {
                if(res.code==5003){
                    top.layer.close(index);
                    top.layer.msg(res.msg);
                    var index1=parent.layer.getFrameIndex(window.name)
                    parent.layer.close(index1);
                    parent.location.reload();
                }else{
                    layer.msg(res.msg);
                }
            },"json");
        });

        //执行计划按钮
        $("#executePlan").click(function () {
            // $.ajax({
            //     url:"toExecutePlan.do"//跳转页面
            // });

            var index=layui.layer.open({
                title:"执行计划",
                type:2,
                content:"toExecutePlan.do",//由于type是2，所以content相当于是url
                success:function (layero,index) {
                    var body = layui.layer.getChildFrame('body', index);//这个是传值
                    body.contents().find(".chanNo").val($("#chanNo").val());//在这个打开的页面中找到对应的输入框然后赋值
                    body.contents().find(".chanDueDate").val($("#chanNo").val());
                    body.contents().find(".chanCustName").val($("#chanCustName").val());
                    body.contents().find(".chanSource").val($("#chanSource").val());
                    body.contents().find(".chanRate").val($("#chanRate").val());
                    body.contents().find(".chanTitle").val($("#chanTitle").val());
                    body.contents().find(".chanLinkman").val($("#chanLinkman").val());
                    body.contents().find(".chanTelephone").val($("#chanTelephone").val());
                    body.contents().find(".chanDescription").val($("#chanDescription").val());
                    body.contents().find(".chanDueTo").val($("#chanDueTo").val());
                    body.contents().find(".chanDueDate").val($("#chanDueDate").val());
                }
            });layui.layer.full(index);//全屏显示
        });




        // //测试的按钮
        // $("#btn1").click(function () {
        //     alert($("#text1").val());
        //     $("#text1").attr("disabled",true);
        // });
        // $("#btn2").click(function () {
        //     alert($("#text1").val());
        //     $("#text1").attr("disabled",false);
        // });
        // $("#btn3").click(function () {
        //     alert($("#text1").val());
        //     $("#text1").attr('class','layui-hide');//还有一个removeAttr
        // });







    });
</script>
</body>
</html>